package cn.wjssl.domain.strategy.service.rule.tree.factory;

import cn.wjssl.domain.strategy.model.valobj.RuleLogicCheckTypeVO;
import cn.wjssl.domain.strategy.model.valobj.RuleTreeVO;
import cn.wjssl.domain.strategy.service.rule.tree.ILogicTreeNode;
import cn.wjssl.domain.strategy.service.rule.tree.factory.engine.IDecisionTreeEngine;
import cn.wjssl.domain.strategy.service.rule.tree.factory.engine.impl.DecisionTreeEngine;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 决策树装配工厂
 */
@Slf4j
@Service
public class DefaultTreeFactory {

    // 获取所有的决策节点
    @Resource
    private Map<String, ILogicTreeNode> logicMap;

    // 获取决策引擎, 需要把决策树导入, 里面是实现决策树过滤的业务
    public IDecisionTreeEngine openLogicTree(RuleTreeVO ruleTreeVO) {
        return new DecisionTreeEngine(logicMap, ruleTreeVO);
    };


    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class StrategyAwardVO {
        /** 抽奖奖品ID - 内部流转使用 */
        private Integer awardId;
        /** 抽奖奖品规则 */
        private String awardRuleValue;
    }

    // 决策树行为对象
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class TreeActionEntity {
        private RuleLogicCheckTypeVO ruleLogicCheckType;
        private StrategyAwardVO strategyAwardVO;
    }

}
